<?php
namespace common\models;
use yii\db\ActiveRecord;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/26
 * Time: 10:00
 */
class Address extends ActiveRecord {
    public static function tableName()
    {
        return "address";
    }

    public function attributeLabels()
    {
        return
            [
                'id'=>'操作id',
                'user_id'=>'用户id',
                'name'=>'收货昵称',
                'mobile'=>'手机号',
                'province'=>'省',
                'city'=>'市',
                'area'=>'区',
                'district'=>'具体地址',
                'status'=>'０非默认　１默认',
                'create_time'=>'添加时间',
                'update_time'=>'修改时间',
            ];

    }
    public function rules()
    {
        return[
            [['id', 'user_id','status','create_time','update_time'], 'integer'],
            [['province','city','area','district','name','mobile'], 'string'],
        ];
    }

    /**
     * 收货地址
     * @param $uid
     * @param int $type
     * @return array|ActiveRecord[]
     */
    public function GetAddressList($uid){

        $address = Address::find()->where(['user_id'=>$uid])->asArray()->orderBy(['status'=>SORT_DESC,'create_time'=>SORT_DESC])->all();

        foreach ($address as &$val){
            $newstr = mb_substr($val['name'],-1);
            $val['name'] = '*'.$newstr;
            $newMobile1 = substr($val['mobile'], 0, 3).'****'.substr($val['mobile'], 7);
            $val['mobile'] = $newMobile1;
        }
        return $address;
    }
}
